import Vue from 'vue'
import VueRouter from 'vue-router'

import NProgress from 'nprogress'
import 'nprogress/nprogress.css'

NProgress.configure({ showSpinner: false })

/**
 * 重写路由的push方法
 * 解决，相同路由跳转时，报错
 * 添加，相同路由跳转时，触发watch (针对el-menu，仅限string方式传参，形如"view?id=5")
 */
 const originalPush = VueRouter.prototype.push;
 VueRouter.prototype.push = function push(location, onResolve, onReject) {
     if (onResolve || onReject) return originalPush.call(this, location, onResolve, onReject);
     return originalPush.call(this, location).catch((err) => err);
 };

 Vue.use(VueRouter)

const routes = [
    {
        "path":"/login",
        "name":"login",
        component: () => import('@/pages/common/login/login.vue'),
    },
    {
        path: '/',
        name: 'main',
        component: () => import('@/pages/main/main.vue'),
        children: [
            // form
            {
                "path":"/form/base",
                "name":"form_base",
                component: () => import('@/pages/demo/form/base/base.vue'),
            },
            {
                "path":"/form/step",
                "name":"form_step",
                component: () => import('@/pages/demo/form/step/step.vue'),
            },
            {
                "path":"/form/advanced",
                "name":"form_advanced",
                component: () => import('@/pages/demo/form/advanced/advanced.vue'),
            },
            // table
            {
                "path":"/table/base",
                "name":"table_base",
                component: () => import('@/pages/demo/table/base/base.vue'),
            },
            {
                "path":"/table/advanced/article",
                "name":"table_advanced_article",
                component: () => import('@/pages/demo/table/advanced/article/article.vue'),
            },
            {
                "path":"/table/advanced/module",
                "name":"table_advanced_module",
                component: () => import('@/pages/demo/table/advanced/module/module.vue'),
            },
            // account
            {
                "path":"/account/base",
                "name":"account_base",
                component: () => import('@/pages/demo/account/base/base.vue'),
            },
            {
                "path":"/account/set",
                "name":"account_set",
                component: () => import('@/pages/demo/account/set/set.vue'),
            },
            {
                "path":"/account/set",
                "name":"account_set",
                component: () => import('@/pages/demo/account/set/set.vue'),
                children:[
                    {
                        "path":"base",
                        "name":"account_set_base",
                        component: () => import('@/pages/demo/account/set/other/base.vue'),
                    },
                    {
                        "path":"security",
                        "name":"account_set_security",
                        component: () => import('@/pages/demo/account/set/other/security.vue'),
                    },
                    {
                        "path":"privacy",
                        "name":"account_set_privacy",
                        component: () => import('@/pages/demo/account/set/other/privacy.vue'),
                    },
                    {
                        "path":"tripartite",
                        "name":"account_set_tripartite",
                        component: () => import('@/pages/demo/account/set/other/tripartite.vue'),
                    },
                    {
                        "path":"message",
                        "name":"account_set_message",
                        component: () => import('@/pages/demo/account/set/other/message.vue'),
                    }
                    
                ]
            },
            {
                "path":"/account/role",
                "name":"account_role",
                component: () => import('@/pages/demo/account/role/role.vue'),
            },

            // dashboard
            {
                "path":"/dashboard/analysis",
                "name":"dashboard_analysis",
                component: () => import('@/pages/demo/dashboard/analysis/analysis.vue'),
            },
            {
                "path":"/dashboard/data_v",
                "name":"dashboard_data_v",
                component: () => import('@/pages/demo/dashboard/data_v/data_v.vue'),
            },
            
            
            
        ]
    },
]

const router = new VueRouter({
    routes
})

router.beforeEach((to, from, next) => {
    NProgress.start()
    next()
})

router.afterEach(() => {
    NProgress.done()
})

export default router
